package sort;

import utils.Common;

/**
 * @author or2
 */
public class Select {

    public static <E extends Comparable<E>> void sort(E[] arr) {
        int length = arr.length;

        for (int i = 0; i < length; i++) {

//            在arr[i,length)中选择最小进行交换
            int minIndex = i;
            for (int j = i; j < length; j++) {
                if (arr[j].compareTo(arr[minIndex]) < 0) {
                    minIndex = j;
                }
            }

            Common.swapArray(arr, i, minIndex);
        }
    }

    public static void main(String[] args) {
        Integer[] ints = new Integer[]{2,3,1,5,7,6};
        sort(ints);
        for (Integer anInt : ints) {
            System.out.print(anInt + "\t");
        }
    }
}
